<div class="tree" id="site_tree"></div>
<script type="text/javascript">
	function load_tree_menu() 
	{
		var first = 0;
		jQuery("#site_tree").jstree(
		{
			"plugins" : [ "themes", "json_data", "ui", "types" ],
			"json_data" : 
			{ 
				"ajax" : {
	                // the URL to fetch the data
	                "url" : "ajax.php<?php echo $commander->getFormAction('ajax'); ?>&ajax=menu",
	                // the `data` function is executed in the instance's scope
	                // the parameter is the node being loaded
	                // (may be -1, 0, or undefined when loading the root nodes)
					<?php 
					$conPrefix = 'm_';
					if($commander->getCon() == 8)
					{ $conPrefix = 'shop_m_'; }
					if($commander->getCon() == 6)
					{ $conPrefix = 'adtype_'; }
					?>
	                "data" : function (n) {
	                    // the result is fed to the AJAX request `data` option
	                    return {
	                        "operation" : "getchildren",
	                        "p" : n.attr ? n.attr("id").replace("<?php $conPrefix; ?>","") : 1
	                    };
	                }
	            },
				"correct_state" : false
			},
			"types" : 
			{
	            // I set both options to -2, as I do not need depth and children count checking
	            // Those two checks may slow jstree a lot, so use only when needed
	            "max_depth" : -2,
				"max_children" : -2,
	            // I want only `drive` nodes to be root nodes
	            // This will prevent moving or creating any other type as a root node
	            "valid_children" : [ "site", "sitemap-item-folder", "shop", "survey", "survey", "fleet", "access-controll" ],
	            "types" : {
					// The `root` node
	                "site" : {
	                    // can have files and folders inside, but NOT other `drive` nodes
	                    "valid_children" : [ "default", "sitemap-item-folder", "sitemap-item", "shop" ],
	                    "start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false
	                },
					/* Shop Types */
					"access-controll" : {  "start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false  },
					"form-manager" : 
					{  
						"valid_children" : [ "form" ],
						"start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false  
					},
					"advertiser" : 
					{  
						"valid_children" : [ "adtypes", "adcategories" ],
						"start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false  
					},
					/* Shop Types */
					"shop" : {
	                    //"valid_children" : [ "default", "sitemap-item-folder", "sitemap-item" ],
	                    "start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false
	                },
					"exe" : 
					{
	                    "valid_children" : [ "exe_tree_import", "exe_tree_export" ],
	                    "start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false
	                },
					"exe_1" : 
					{ "start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false  },
					"exe_2" : 
					{ "start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false  },
					"shipping" :
					{
	                    "valid_children" : [ "shipping_method" ],
	                    "start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false
	                },
					/* Shop Types End */
					"fleet" : {
	                    // can have files and folders inside, but NOT other `drive` nodes
	                    "valid_children" : [ "default", "sitemap-item-folder", "sitemap-item" ],
						"icon" : {
	                        "image" : "<?php echo SYSICONS_URL.'treemenu/schedule_16.png'; ?>"
	                    },
	                    // those prevent the functions with the same name to be used on `drive` nodes
	                    // internally the `before` event is used
	                    "start_drag" : false, "move_node" : false, "delete_node" : false, "remove" : false
	                },
	                // The `folder` type
	                "sitemap-item-folder" : {
	                    // can have files and other folders inside of it, but NOT `drive` nodes
	                    "valid_children" : [ "default", "folder" ],
	                    "icon" : { "image" : "<?php echo SYSICONS_URL.'treemenu/folder_html_16.gif'; ?>" }
	                },
					// The default type
	                "sitemap-item" : {
	                    // I want this type to have no children (so only leaf nodes)
	                    // In my case - those are files
	                    // If we specify an icon for the default type it WILL OVERRIDE the theme icons
						"valid_children" : "none",
	                    "icon" : { "image" : "<?php echo SYSICONS_URL.'treemenu/page_18.gif'; ?>" }
	                },
	                // The default type
	                "default" : {
	                    // I want this type to have no children (so only leaf nodes)
	                    // In my case - those are files
	                    "valid_children" : "default",
	                    // If we specify an icon for the default type it WILL OVERRIDE the theme icons
	                    "icon" : { "image" : "<?php echo SYSICONS_URL.'treemenu/page_18.gif'; ?>" }
	                }
	            }
	        },
			"ui" : {
			<?php
			if($_REQUEST['m'] > 0)
			{ 
				if($commander->getCon() == 1)
				{ echo '"initially_select" : [ "m_'.$_REQUEST['m'].'" ]'; }
				if($commander->getCon() == 8)
				{
					if($_REQUEST['m'] > 0)
					{ echo '"initially_select" : [ "shop_m_'.$_REQUEST['m'].'" ]'; }
					else
					{ echo '"initially_select" : [ "con_8" ]'; }
				}
			}
			if($commander->getCon() == 6)
			{
				if($_GET['type'] > 0)
				{ echo '"initially_select" : [ "adtype_'.$_GET['type'].'" ]'; }
				if($_GET['cat'] > 0)
				{ echo '"initially_select" : [ "adcat_'.$_GET['cat'].'" ]'; }
				
				if($_GET['list'] == 'ad')
				{
					if(($_GET['archived'] > 0) || ($_GET['deleted'] > 0))
					{ 
						if($_GET['archived'] > 0)
						{ echo '"initially_select" : [ "ad_archived" ]';  }
						if($_GET['deleted'] > 0)
						{ echo '"initially_select" : [ "ad_deleted" ]';  }
					}
					else
					{
						if(($_GET['typeId'] > 0) || ($_GET['catId'] > 0))
						{
							if($_GET['typeId'] > 0)
							{ echo '"initially_select" : [ "ad_typeId_'.$_GET['typeId'].'" ]'; }
							if($_GET['catId'] > 0)
							{ echo '"initially_select" : [ "ad_catId_'.$_GET['catId'].'" ]'; }
						}
						else
						{ echo '"initially_select" : [ "ads" ]'; }
					}
				}
				else
				{
					if($_GET['typeId'] > 0)
					{ echo '"initially_select" : [ "ad_typeId_'.$_GET['typeId'].'" ]'; }
					if($_GET['catId'] > 0)
					{ echo '"initially_select" : [ "ad_catId_'.$_GET['catId'].'" ]'; }
				}
			}
			?>
			},
			"core" : 
			{
				"html_titles" : true,
				"animation" : 100,
				<?php
					echo '"initially_open" : [ ';		  
					if($katana->OpenMenus)
					{
						if($commander->getCon() == 1)
						{
							foreach($katana->OpenMenus as $item)
							{ echo '"m_'.$item['id'].'", '; }
						}
						if($commander->getCon() == 8)
						{
							foreach($katana->OpenMenus as $item)
							{ echo '"shop_m_'.$item['id'].'", '; }
						}
					}
					if($commander->getCon() == 6)
					{
						if($_GET['list'] == 'type')
						{ echo '"adtypes", '; }
						if($_GET['list'] == 'cat')
						{ echo '"adcats", '; }
						if($_GET['list'] == 'ad')
						{
							echo '"ads", ';
							if($_GET['typeId'] > 0)
							{ echo '"ad_typeId_'.$_GET['typeId'].'", '; }
							if($_GET['catId'] > 0)
							{ echo '"ad_catId_'.$_GET['catId'].'", '; }
						}
						else
						{
							if($_GET['typeId'] > 0)
							{ echo '"adcat_type_'.$_GET['typeId'].'", '; }
						}
					}
					if($commander->getCon() > 0)
					{ echo '"con_'.$commander->getCon().'", '; }
					if($_GET['list'] != '')
					{ echo '"'.$_GET['list'].'", '; }		
					echo ']';
				?>
			}
		}).bind("select_node.jstree", function ( event, data) 
		{
			if(first == 0)
			{ first = 1; }
			else
			{ document.location.href = jQuery(".jstree-clicked").attr("href"); }
	    });
	} 
</script>
<?php //print_r($katana); ?>
<?php //print_r($shop); ?>